<?php if (empty($this->data)) : // ถ้าไม่มีข้อมูล                ?>
<?php echo $this->element('dataNotFound'); ?>
<? else : // ถ้ามีข้อมูล                ?>
<?php $paginator->options(array('update' => 'content', 'indicator' => 'indicator', 'url' => array('controller' => 'CustProductSites', 'action' => 'display'))); ?>
<?php echo $this->element('dataCaptionLimit', array('controller' => 'cust_product_sites')); ?>
<?php $cur = $paginator->counter(array('format' => '%start%')); ?>

        <table class="data">
            <thead>
                <tr>
                    <th class="no"><?php echo $paginator->sort('No', 'id'); ?></th>
                    <th class="text-left">
                        <div class="inline-block bold" style="width: 33%;"><?php echo $paginator->sort('Stock Code', 'CustProductSite.stock_code'); ?></div>
                        <div class="inline-block" style="width: 33%;">&nbsp;Vendor Part no.</div>
                        <div class="inline-block" style="width: 33%;"><?php echo $paginator->sort('Category', 'Product.Category.name'); ?></div>
                        <br />
                        <div class="inline-block" style="width: 33%;"><?php echo $paginator->sort('Brand', 'Product.Brand.name'); ?></div>
                        <div class="inline-block" style="width: 33%;"><?php echo $paginator->sort('Model', 'Product.model'); ?></div>
                        <div class="inline-block" style="width: 33%;">&nbsp;Location</div>
                        <div><?php echo $paginator->sort('Description', 'Product.title'); ?></div>
                    </th>
                    <th width="70px"><?php echo $paginator->sort("Current Stock", 'CustProductSite.current_stock'); ?></th>
                    <th width="70px"><?php echo $paginator->sort('Reserved Qty.', 'CustProductSite.reserve_qty'); ?></th>
                    <th width="60px"><?php echo $paginator->sort('Min Stock', 'CustProductSite.min_stock'); ?></th>
                    <th width="60px"><?php echo $paginator->sort('Max Stock', 'CustProductSite.max_stock'); ?></th>
                    <th width="50px" style="min-width: 50px;">&nbsp;</th>
                </tr>
            </thead>
            <tbody>
        <?php
        foreach ($this->data as $i => $data):
            $current_stock = $data['CustProductSite']['current_stock'];
            $min_stock = $data['CustProductSite']['min_stock'];
            $max_stock = $data['CustProductSite']['max_stock'];
        ?>
            <tr class="<?php
            if (empty($max_stock) && empty($min_stock) || $current_stock == $max_stock) {
                echo (($i + 1) % 2 == 0) ? 'even-cell' : 'odd-cell';
            } else {
                echo $current_stock <= $min_stock ? 'min-stock' : ($current_stock < $max_stock ? 'max-stock' : ($current_stock > $max_stock ? 'green' : ''));
            }
        ?>">
            <td  class="center"><?php echo $i + 1; ?></td>
            <td style="min-width: 600px;">
                <div class="inline-block bold" style="width: 33%;"><?php echo $data['CustProductSite']['stock_code']; ?></div>
                <div class="inline-block" style="width: 33%;"><?php echo $data['CustProductSite']['dispatch_from'] == ITS_PREFIX ? $data['Product']['part_no'] : $data['Product']['supplier_part_no']; ?></div>
                <div class="inline-block" style="width: 33%;"><?php echo isset($data['Product']['Category']['name']) ? $data['Product']['Category']['name'] : '-'; ?></div>
                <br />
                <div class="inline-block" style="width: 33%;"><?php echo $data['Product']['Brand']['name']; ?></div>
                <div class="inline-block" style="width: 33%;"><?php echo $data['Product']['model']; ?></div>
                <div class="inline-block" style="width: 33%;"><?php echo isset($data['ProductSerial'][0]) && isset($data['ProductSerial'][0]['CustLocation']['name'])? $data['ProductSerial'][0]['CustLocation']['name']: '-'; ?></div>
                <div><?php echo!empty($data['CustProductSite']['text']) ? $data['CustProductSite']['text'] : $data['Product']['text']; ?></div>
            </td>
            <td class="text-right">&nbsp;<?php echo $current_stock; ?></td>
            <td class="text-right">&nbsp;<?php echo $data['CustProductSite']['reserve_qty']; ?></td>
            <td class="text-right">&nbsp;<?php echo isset($data['CustProductSite']['min_stock'])? $data['CustProductSite']['min_stock']: '-'; ?></td>
            <td class="text-right">&nbsp;<?php echo isset($data['CustProductSite']['max_stock'])? $data['CustProductSite']['max_stock']: '-'; ?></td>
            <td>
                <?php echo $ajax->link($html->image('icon/edit.png', array('title' => 'view', 'alt' => 'view')), '/cust_product_sites/view/' . $data['CustProductSite']['id'],
                        array('indicator' => 'indicator', 'update' => 'content'), null, false); ?>&nbsp;
                <?php
                echo $ajax->link($html->image('icon/popup.png', array('alt' => 'Index information')),
                        array('controller' => 'products_serials', 'action' => 'popup_cust_view', $data['CustProductSite']['id']),
                        array('update' => 'content', 'position' => 'bottom', 'indicator' => 'indicator'), null, false);
                ?>
            </td>
        </tr>
        <?php endforeach; ?>
            </tbody>
        </table>
<?php echo $this->element('paging'); ?>
                <div class="caption">
                    <span class="min-stock rect"></span> Current Stock is less than Min Stock.
                    <span class="max-stock rect"></span> Current Stock is less than Max Stock.
                    <span class="green rect"></span> Current Stock is higher than Max Stock.
                </div>

<? endif; ?>
<?php //debug($this->data); ?>